package view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;

import javax.swing.JButton;
import javax.swing.JInternalFrame;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.view.JasperViewer;
import util.datebase.ConexionDB;

public class FrmReporte extends JInternalFrame {


	
	public FrmReporte() {
		setBounds(100, 100, 488, 369);
		getContentPane().setLayout(null);
		
		JButton btnNewButton = new JButton("Generar Inventario");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				/*String codigo = tlbRegistroOrdenServicio.getValueAt(row,
						0).toString();
*/
				String fileName = System.getProperty("user.dir")+ "/util/report1.jrxml";     // la ruta

				
				JasperReport masterReport = null;
				try {
					masterReport = (JasperReport) JRLoader
							.loadObjectFromFile(fileName);

				//	Map parametro = new HashMap();

				///.put("parOSCodigo", codigo);  // variables de entrada en 
					//parametro.put("PATH_LOGO", fileLogo);
					
					Connection conn=new ConexionDB().getConexion();
					
					JasperPrint jp = JasperFillManager.fillReport(masterReport, null,conn);  // conecxion a la base de datos
					JasperViewer viewer = new JasperViewer(jp, false);
					viewer.setTitle("Orden de Servicio " );
					viewer.setVisible(true);
				} catch (JRException ex) {
				System.out.println("Error"+ex);
				}
				
			}
		});
		btnNewButton.setBounds(123, 46, 215, 33);
		getContentPane().add(btnNewButton);
		
		JButton btnGenerarListaPersona = new JButton("Generar Lista Persona");
		btnGenerarListaPersona.setBounds(123, 110, 215, 33);
		getContentPane().add(btnGenerarListaPersona);
		
		JButton btnNewButton_1 = new JButton("Generar Lista Area");
		btnNewButton_1.setBounds(123, 172, 215, 33);
		getContentPane().add(btnNewButton_1);

	}
}
